package org.third.spring.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

public class SpringTaskTest {

    public static class UserLoaderTask {
        public void loadUsers() {
            logger.info("loading users");
        }
    }

    @Component
    public static class GroupLoaderTask {
        @Scheduled(fixedDelay=6000)
        public void loadUsers() {
            logger.info("loading groups");
        }
    }

    public static class UserLoaderTaskTrigger implements Trigger {
        @Override
        public Date nextExecutionTime(TriggerContext triggerContext) {
            return new Date(System.currentTimeMillis() + 5000);
        }
    }

    private static final Logger logger = LoggerFactory.getLogger(SpringTaskTest.class);

    public static void main(String[] args) {
        ApplicationContext bf = new ClassPathXmlApplicationContext(SpringTaskTest.class.getName().replaceAll("\\.", "/") + ".xml");
    }
}